package MoC;

//////////////////////////////////////////////////////////////////////////
//// Message
/**
@author Ivan Jeukens
@version v 0.1 5/2/2002
*/
public class Message {

    public Message(String actor, int phase, int moc, int status, int code, 
             String summary) {
        _actorName = actor;
        _phase = phase;
        _status = status;
        _code = code;
        _summary = summary;
        _moc = moc;
    }

    // Codigos do MoCs
    public static final int NOMOC = 1;  // para msg independentes de moc
    public static final int SDF = 2;
    public static final int SR = 3;
    public static final int DE = 4;
    public static final int PN = 5;
    public static final int CSP = 6;

    // As etapas
    public static final int PREPROCESS = 1;
    public static final int CONCLUSION_PHASE = 2;
    public static final int MOCVALIDATION = 3;
    public static final int SDFVALIDATION = 4;
    public static final int SRVALIDATION = 5;

    // Os diferentes status
    public static final int UNDEF = 0;
    public static final int WARNING = 1;
    public static final int ERROR = 2;
    public static final int CONCLUSION = 3;
    public static final int INFORMATION = 4;

    // Codigo de erro

    // Genericos
    public static final int EXCEPTION = 1;
    public static final int CONTAINEDCOMPOSITEINVALID = 38;
    public static final int SAMPLERATE = 40;
    public static final int VALIDASATOMIC = 43;

    // preprocessamento 1
    public static final int INVALID_MOC_NAME = 2;
    public static final int VALUE_REPEATED = 3;
    public static final int INVALID_TYPE = 4;
    public static final int INCONSISTENT_MOCPAR = 5;
    public static final int NONSTRICTACTOR = 6;
    public static final int ACTORNOTOPAQUE = 14;
    public static final int INSTANCESPARAMETERSERROR = 16;

    // preprocessamento 2
    public static final int DISTINCT_GETDIRECTOR = 7;
    public static final int GETDIRECTOR = 8;
    public static final int NONSR_NONSTRICT = 9;
    public static final int GENERIC_ACTOR = 10;
    public static final int SDFPORT_NOSDFMETHOD = 11;
    public static final int SDFPORT_NOTSDFSPECIFIC = 12;
    public static final int SDFMETHOD_NOTSDFSPECIFIC = 13;
    public static final int SDFSPECIFIC = 15;
    public static final int DEACTOR_NOTDESPECIFIC = 17;
    public static final int SPECIFIC_ACTOR = 18;
    public static final int HASDEIOPORTS = 19;
    public static final int HASDEMETHODS = 20;
    public static final int CSPACTOR_NOTCSPSPECIFIC = 21;
    public static final int HASCSPMETHODS = 22;
    public static final int VALIDSDF_SPECIFICSR = 23;
    public static final int VALIDSDF_SPECIFICDE = 24;
    public static final int VALIDSR_SPECIFICDE = 25;
    public static final int VALIDSDF_SPECIFICCSP = 26;
    public static final int VALIDSR_SPECIFICCSP = 27;
    public static final int MULTIMOC_SPECIFIC = 42;
    public static final int ISTIMED = 44;

    // sdf validation
    public static final int LOOP_WITH_EXIT = 28;
    public static final int LOOP_NOT_COUNTABLE = 29;
    public static final int INVALID_CHANNELINDEX = 30;
    public static final int INVALID_VECTORLENGTH = 31;
    public static final int LOOP_INSIDE_GETWIDTH = 32;
    public static final int NONCONSTANTSAMPLERATE = 33;
    public static final int NOTSCHEDULABLE = 41; 
    

    // sr validation
    public static final int NONUNITARYSAMPLERATE = 34;
    public static final int NOTISKNOWN = 35;    
    public static final int INVALIDCONTAINEDCOMPOSITE = 36;
    public static final int NOTSRSCHEDULABLE = 37;
    public static final int PORTSDEPENDENCIES = 39;
    public static final int PRODINPOSTFIRE = 45;

    // conclusao
    public static final int CONCLUSION_CODE = 46;

    ///////////////////////////////////////////////////////////////////
    ////                        public methods                     ////

    public static String statusToString(int status) {
        if(status < WARNING || status > INFORMATION) return "UNDEF";
        switch(status) {
            case WARNING: return "Warning";
            case ERROR: return "Error";
            case INFORMATION: return "Information";
            case CONCLUSION: return "Conclusion";
        }
        return "Undefined";
    }

    public static String mocToString(int moc) {
        switch(moc) {
            case SDF: return "SDF";
            case SR: return "SR";
            default: return "Independent";
        }
    }
    
    public static int stringToMoC(String moc) {
        if(moc.equals("SDF")) {
            return SDF;
        }
        else
        if(moc.equals("DE")) {
            return DE;
        }
        else
        if(moc.equals("SR")) {
            return SR;
        }
        else
        if(moc.equals("PN")) {
            return PN;
        }
        else
        if(moc.equals("CSP")) {
            return CSP;
        }
        return NOMOC;
    }
    
    public static String phaseToString(int phase) {
        switch(phase) {
            case PREPROCESS: return "Preprocess";
            case MOCVALIDATION: return "MOC Validation";
            case SDFVALIDATION: return "SDF Validation";
            case SRVALIDATION: return "SR Validation";
            case CONCLUSION_PHASE: return "Conclusion";
        }
        return null;
    }

    public int getStatus() {
        return _status;
    }

    public int getMoC() {
        return _moc;
    }

    public int getCode() {
        return _code;
    }

    public String getSummary() {
        return _summary;
    }

    public void setText(String text) {
        _text = text;
    }

    public String getText() {
        return _text;
    }

    public int getPhase() {
        return _phase;
    }

    public void setLocation(MessageLocation loc) {
        _location = loc;
    }

    public MessageLocation getLocation() {
        return _location;
    }

    public String getActorName() {
        return _actorName;
    }
    
    ///////////////////////////////////////////////////////////////////
    ////                      protected variables                  ////

    protected int _phase;
    protected int _code;
    protected int _status;
    protected String _summary;
    protected String _text;
    protected int _moc;
    protected String _actorName;

    protected MessageLocation _location;

    ///////////////////////////////////////////////////////////////////
    ////                        private variables                  ////
}
